#coding:utf-8

from flask import Flask, request
import userBussiness
import json,time
import appconf,hashlib,os
from flask import send_from_directory

app = appconf.app

@app.route('/login', methods=['POST'])
def userInfo_login():
    content = request.json
    userInfo = userBussiness.login(content)

    return json.dumps({'errorCode': '', 'data': userInfo})

@app.route('/register', methods=['POST'])
def userInfo_register():
    content = request.json
    id = userBussiness.register(content)
    return json.dumps({'errorCode': '', 'id': id})

@app.route('/user/update', methods=['POST'])
def userInfo_update():
    content = request.json
    id = userBussiness.updateUserInfo(content)
    return json.dumps({'errorCode': '', 'id': id})
@app.route('/user/delete', methods=['POST'])
def user_delete():
    content = request.json
    id = userBussiness.deleteUser(content['id'])
    return json.dumps({'errorCode': '', 'id': id})

@app.route('/logout')
def userInfo_logout():
    token = request.args.get("token")
    openId = request.args.get("openId")
    data = userBussiness.logout(token,openId)
    return json.dumps({'errorCode': '', 'id': data})

@app.route('/user/list')
def userInfo_list():
    page = request.args.get("page")
    limit = request.args.get("limit")
    items = userBussiness.userList(page,limit)
    return json.dumps({'errorCode': '', 'data': items[0], "count": items[1]})



@app.route('/user/all')
def userInfo_all():
    items = userBussiness.allUser()
    return json.dumps({'errorCode': '', 'data':items})